package com.bytedance.common.utility.collection;

import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.HashMap;

public final class e<K,V> {
    final class a extends WeakReference {
        final Object a;

        public a(Object arg1, Object arg2, ReferenceQueue arg3) {
            super(arg2, arg3);
            this.a = arg1;
        }
    }

    public final HashMap a;
    private final ReferenceQueue b;

    public e() {
        this.a = new HashMap();
        this.b = new ReferenceQueue();
    }

    public final Object a(Object arg3) {
        Object v0;
        Object v1 = null;
        this.a();
        if(arg3 == null) {
            v0 = v1;
        }
        else {
            v0 = this.a.get(arg3);
            v0 = v0 != null ? ((a)v0).get() : v1;
        }

        return v0;
    }

    public final void a() {
        while(true) {
            Reference v0 = this.b.poll();
            if(v0 == null) {
                return;
            }

            if(this.a.isEmpty()) {
                continue;
            }

            this.a.remove(((a)v0).a);
        }
    }

    public final void a(Object arg3, Object arg4) {
        if(arg3 != null && arg4 != null) {
            this.a.remove(arg3);
            this.a();
            this.a.put(arg3, new a(arg3, arg4, this.b));
        }
    }

    public final int b() {
        this.a();
        return this.a.size();
    }

    public final void b(Object arg2) {
        this.a();
        if(arg2 != null) {
            this.a.remove(arg2);
        }
    }
}

